package Model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;


import Configuration.Account;
import Controller.Tasker;

public class DAOConfigurations {
	private Account account;
	private Tasker tasker;
	private String file="docs\\conf.tasker";
	public DAOConfigurations(Tasker tasker)
	{
		this.tasker=tasker;
		readAccount();
	}
	public void readAccount()
	{
		try {
			BufferedReader bf = new BufferedReader(new FileReader(file));
			String link = bf.readLine().split("=")[1];
			int r_typ = Integer.parseInt(bf.readLine().split("=")[1]);
			int r_time = Integer.parseInt(bf.readLine().split("=")[1]);
			boolean starup = Boolean.parseBoolean(bf.readLine().split("=")[1]);
			String back_link = bf.readLine().split("=")[1];
			int back_type = Integer.parseInt(bf.readLine().split("=")[1]);
			int back_time = Integer.parseInt(bf.readLine().split("=")[1]);
			boolean back_auto = Boolean.parseBoolean(bf.readLine().split("=")[1]);
			account = new Account(link, r_typ, r_time, starup, back_link, back_type, back_time, back_auto, tasker);
			bf.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void writeAccount()
	{
		try {
			PrintWriter pw = new PrintWriter(new File(file));
			pw.println("link="+account.getLink());
			pw.println("refresh_type="+account.getRefresh().getType());
			pw.println("refresh_time="+account.getRefresh().getMin());
			pw.println("startup="+account.isStartup());
			pw.println("backup_link="+account.getBackup().getBackupLink());
			pw.println("backup_type="+account.getBackup().getBackupType());
			pw.println("backup_time="+account.getBackup().getBackupTime());
			pw.println("backup_auto="+account.getBackup().isBackupAuto());
			pw.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}